package design;

/**
 * Created by zhangyanfei on 2019/7/8.
 *
 * @author zhangyanfei
 * @date 2019/07/08
 */
public class Scope {
    public static final Scope LITE = new Scope(0);

    public static final Scope PRODUCT_INFO = new Scope(1);

    public static final Scope ORDER_INFO = new Scope(2);

    public int scope;

    Scope(int scope) {
        this.scope = scope;
    }

    public static class ScopeBuilder {
        int scope = LITE.scope;

        /**
         * 扩展scope范围
         *
         * @param extendScope
         * @return
         */
        public ScopeBuilder exend(Scope extendScope) {
            this.scope = extendScope.scope | this.scope;
            return this;
        }

        public Scope build() {
            return new Scope(this.scope);
        }
    }

    public boolean isExtended(Scope source) {
        if (source == null) {
            return false;
        }
        return (this.scope & source.scope) == this.scope;
    }
}
